package com.zb.entity.dto;

import com.zb.entity.ZjAdmWxTemplate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/7/12 0012
 **/
@Data
@ApiModel("微信消息模板实体")
public class WxTemplateDto {
    @ApiModelProperty(value = "主健ID，新增时不必传，修改时必传")
    private Long id;

    @NotBlank(message = "模板编号不能为空")
    @Length(max = 60, message = "模板编号长度字符限制在60个以内")
    @ApiModelProperty(value = "模板库中模板的编号，有“TM**”和“OPENTMTM**”等形式,对于类目模板，为纯数字ID", required = true)
    private String templateIdShort;

    @NotBlank(message = "模板标题不能为空")
    @Length(max = 20, message = "模板标题长度字符限制在20个以内")
    @ApiModelProperty(value = "标题", required = true)
    private String name;

    @NotBlank(message = "所属类目不能为空")
    @Length(max = 20, message = "所属类目长度字符限制在20个以内")
    @ApiModelProperty(value = "所属类目", required = true)
    private String category;

    @NotBlank(message = "场景说明不能为空")
    @Length(max = 15, message = "场景说明长度字符限制在15个以内")
    @ApiModelProperty(value = "场景说明", required = true)
    private String remark;

    @NotBlank(message = "应用模块不能为空")
    @Length(max = 20, message = "应用模块长度字符限制在20个以内")
    @ApiModelProperty(value = "应用模块", required = true)
    private String module;

    @NotBlank(message = "接收角色不能为空")
    @Length(max = 50, message = "接收角色长度字符限制在50个以内")
    @ApiModelProperty(value = "接收角色", required = true)
    private String role;

    @NotBlank(message = "示例内容消息不能为空")
    @Length(max = 500, message = "示例内容消息长度字符限制在500个以内")
    @ApiModelProperty(value = "示例内容消息", required = true)
    private String example;

    @Valid
    @Size(min = 1, message = "微信消息模板内容至少要传一项")
    @ApiModelProperty(value = "微信消息模板内容", required = true)
    private List<WxTemplateContent> content;

    @ApiModelProperty(value = "微信消息模板内容ID，删除时传ID")
    private List<Long> contentIds;

    public static ZjAdmWxTemplate dtoToBean(WxTemplateDto dto) {
        ZjAdmWxTemplate template = new ZjAdmWxTemplate();
        template.setId(dto.getId());
        template.setTemplateIdShort(dto.getTemplateIdShort());
        template.setName(dto.getName());
        template.setCategory(dto.getCategory());
        template.setRemark(dto.getRemark());
        template.setModule(dto.getModule());
        template.setRole(dto.getRole());
        template.setExample(dto.getExample());
        return template;
    }


}
